<template>
	<view :style="wrapperStyle" class="explosion">
		<view class="common-hd" mode="widthFix" v-if="logoUrl">
			<image class="title-img" mode="widthFix" :src="logoUrl"></image>
		</view>
		<view class="mer-box">
			<!-- 多行 -->
			<block v-if="tabConfig == 0">
				<view class="mer-item bg-f" v-for="(item, index) in brandList" :key="index" :style="merHdStyle">
					<view class="mer-hd" @click="goStore(item.mer_id)">
						<image :src="item.mer_banner"></image>
						<view class="mer-name mutip-line">
							<image :src="item.mer_avatar"></image>
							<view class="txt line1">{{ item.mer_name }}</view>
							<template v-if="dataConfig.distanceShow && dataConfig.distanceShow.val && item.distance">
								<view class="vertical-line" />
								<view style="margin-right: 10rpx;font-weight: initial;">
									{{ item.distance }}
								</view>
							</template>
							<text v-if="item.type_name" class="store_type" :style="'background:' + themeColor">{{ item.type_name
							}}</text>
							<text v-else-if="item.is_trader" class="store_type" :style="'background:' + themeColor">自营</text>
						</view>
					</view>
					<view class="pro-box">
						<navigator :url="`/pages/goods_details/index?id=${itemn.product_id}`" hover-class="none" class="pro-item"
							v-for="(itemn, indexn) in item.all_recommend" :key="indexn">
							<view class="picture">
								<easy-loadimage mode="aspectFit" :image-src="itemn.image"></easy-loadimage>
								<view v-if="itemn.border_pic" :style="{ backgroundImage: `url(${itemn.border_pic})` }"
									class="border-picture">
								</view>
							</view>
							<view v-if="titleShow" class="name line1">{{ itemn.store_name }}</view>
							<view v-if="priceShow" class="price" :style="'color:' + themeColor">
								<priceFormat :price="itemn.price" weight intSize="40" floatSize="26" labelSize="9"></priceFormat>
							</view>
						</navigator>
					</view>
				</view>
			</block>
			<!-- 单行 -->
			<block v-else-if="tabConfig == 2">
				<view class="mer_count">
					<view class="item" v-for="(item, index) in brandList" :key="index" @click="goStore(item.mer_id)">
						<image :src="item.mer_avatar" mode="widthFix"></image>
					</view>
				</view>
			</block>
			<!-- 详情模式 -->
			<template v-else-if="tabConfig == 1">
				<view class="mer-detail-wrap" v-for="(item, index) in brandList" :key="index"
					:style="'border-radius:' + bgStyle + 'rpx'">
					<view class="mer-top-info">
						<image class="mer-avatar" :src="item.mer_avatar" @click="goStore(item.mer_id)" />
						<view class="mer-info">
							<view class="mer-name" @click="goStore(item.mer_id)">
								{{ item.mer_name }}
								<view class="type-tag" v-if="item.mer_type_name" :style="'background:' + themeColor">{{
									item.mer_type_name
									}}</view>
							</view>
							<view class="mer-follow-info">
								{{ getFollowCount(item) }} 人关注
								<template v-if="dataConfig.distanceShow && dataConfig.distanceShow.val && item.distance">
									<view class="vertical-line" />
									<view>
										{{ item.distance }}
									</view>
								</template>
							</view>
						</view>
					</view>

					<view class="product-list-wrapper">
						<view class="product-list">
							<navigator class="product-item" v-for="product of item.all_recommend" :key="product.product_id"
								:url="`/pages/goods_details/index?id=${product.product_id}`" hover-class="none">
								<image :src="product.image" mode="aspectFill" class="product-image" />
								<view class="product-name" v-if="titleShow">{{ product.store_name }}</view>
								<view class="product-price" v-if="priceShow" :style="'color:' + themeColor">
									<priceFormat :price="product.price" weight intSize="14" floatSize="10" labelSize="9" unit="px" />
								</view>
							</navigator>
						</view>
					</view>
				</view>
			</template>
			<view class="more-shop" @click="moreShop">
				<text>更多店铺</text>
				<text class="iconfont icon-ic_rightarrow"></text>
			</view>
		</view>
	</view>
</template>

<script>
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------	
import easyLoadimage from '@/components/easy-loadimage/easy-loadimage.vue';
import { storeList } from '@/api/api.js';
import { mapGetters } from 'vuex';
import { configMap } from '@/utils';
export default {
	computed: configMap(
		['hide_mer_status'],
		{
			...mapGetters(['location']),
			merHdStyle() {
				const { bgStyle } = this;
				const style = {
					'border-radius': `${bgStyle}rpx`
				}
				return Object.entries(style).map(([key, value]) => `${key}: ${value}`).join(';');
			},
			wrapperStyle() {
				const { mbConfig, prConfig, bgColor } = this;
				const style = {
					padding: `${mbConfig}rpx ${prConfig}rpx 0`,
					background: bgColor,
				}

				return Object.entries(style).map(([key, value]) => `${key}: ${value}`).join(';');
			},
		}
	),
	components: {
		easyLoadimage
	},
	props: {
		dataConfig: {
			type: Object,
			default: () => { }
		}
	},
	data() {
		return {
			brandList: [],
			mbConfig: this.dataConfig.mbConfig.val * 2, //页面间距
			prConfig: this.dataConfig.prConfig.val * 2, //背景间距
			logoUrl: this.dataConfig.logoConfig.url,
			bgStyle: this.dataConfig.bgStyle.type ? '24' : 0,
			bgColor: this.dataConfig.bgColor.color[0].item,
			themeColor: this.dataConfig.themeColor.color[0].item,
			tabConfig: this.dataConfig.tabConfig.tabVal, //展示样式
			numConfig: this.dataConfig.numConfig.val,
			titleShow: this.dataConfig.titleShow.val,
			priceShow: this.dataConfig.priceShow.val,
			diy_id: this.dataConfig.did,
			unique: this.dataConfig.timestamp,

		}
	},
	created() { },
	mounted() {
		this.storeMerchant();
	},
	watch: {
		location() {
			this.storeMerchant();
		}
	},
	methods: {
		getFollowCount(item) {
			return item.care_count < 10000 ? item.care_count : (item.care_count / 10000).toFixed(2) + '万'
		},
		// 进店看看
		goStore(id) {
			if (this.hide_mer_status != 1) {
				uni.navigateTo({
					url: `/pages/store/home/index?id=${id}`
				});
			}
		},
		// 更多店铺
		moreShop() {
			uni.navigateTo({
				url: `/pages/store/shopStreet/index?cate_id=&type_id=`
			});
		},
		// 品牌好店
		storeMerchant() {

			const query = {
				diy_id: this.diy_id,
				unique: this.unique,
				page: 1,
				limit: this.numConfig ? this.numConfig : 4,
				is_best: 1,
				...this.location
			};

			if (this.dataConfig.shopsSort) {
				const sort = this.dataConfig.shopsSort.type;
				if (sort == 0) {
					query.order = 'sort';
				} else if (sort == 1 && this.location) {
					query.order = 'range_asc';
				}

			}

			storeList(query).then(res => {
				this.brandList = res.data.list;
			});
		},
	}
};
</script>

<style scoped lang="scss">
.explosion {
	.common-hd {
		display: flex;
		align-items: center;
		justify-content: center;

		.title-img {
			width: 242rpx;
			margin: 20rpx 0;
		}
	}

	.mer-box {
		margin-bottom: 20rpx;

		.mer-item {
			margin-bottom: 20rpx;
			text-align: center;

			.mer-hd {
				position: relative;
				width: 100%;
				height: 200rpx;
				border-radius: 16rpx 16rpx 0 0;
				overflow: hidden;

				image {
					width: 100%;
					height: 100%;
				}

				.mer-name {
					position: absolute;
					left: 20rpx;
					top: 20rpx;
					display: flex;
					max-width: 60%;
					padding: 6rpx 10rpx 6rpx 6rpx;
					border-radius: 26rpx;
					background: #fff;
					font-weight: bold;
					font-size: 12px;
					align-items: center;

					image {
						width: 38rpx;
						height: 38rpx;
						margin-right: 10rpx;
						border-radius: 50%;
					}

					.txt {
						flex: 1;
						line-height: 19px;
						height: 19px;
					}

					.store_type {
						font-size: 18rpx;
						color: #fff;
						background-color: #e93323;
						padding: 0 5px;
						line-height: 30rpx;
						height: 30rpx;
						margin-left: 8rpx;
						border-radius: 68rpx;
					}
				}
			}

			/deep/.easy-loadimage,
			/deep/uni-image,
			image,
			/deep/.loadfail-img {
				width: 100%;
				height: 214rpx;
			}

			.pro-box {
				display: flex;
				// align-items: center;
				padding: 20rpx 20rpx 24rpx 20rpx;
				flex-flow: row nowrap;
				overflow-x: auto;

				.pro-item {
					width: 31.3%;
					margin-right: 3.05%;

					.picture,
					/deep/.easy-loadimage,
					/deep/uni-image,
					/deep/image,
					/deep/.loadfail-img {
						width: 214rpx;
						height: 214rpx;
						position: relative;
						border-radius: 12rpx;
					}

					.sell_out {
						display: flex;
						width: 110rpx;
						height: 110rpx;
						align-items: center;
						justify-content: center;
						border-radius: 100%;
						background: rgba(0, 0, 0, .6);
						color: #fff;
						font-size: 24rpx;
						position: absolute;
						top: 50%;
						left: 50%;
						margin: -55rpx 0 0 -55rpx;

						&::before {
							content: "";
							display: block;
							width: 100rpx;
							height: 100rpx;
							border-radius: 100%;
							border: 1px dashed #fff;
							position: absolute;
							top: 5rpx;
							left: 5rpx;
						}
					}

					.border-picture {
						position: absolute;
						top: 0;
						left: 0;
						width: 100%;
						height: 100%;
						background: center/cover no-repeat;
					}

					.name {
						padding: 6rpx 9rpx;
						margin-top: 6rpx;
					}

					.price {
						margin-top: 5rpx;
						font-size: 28rpx;
						color: $theme-color;
						font-weight: bold;

						text {
							font-size: 28rpx;
						}
					}

					&:last-child {
						margin-right: 0;
					}

					.picture {
						position: relative;
					}

					.border-picture {
						position: absolute;
						top: 0;
						left: 0;
						width: 100%;
						height: 100%;
						background: center/cover no-repeat;
					}
				}
			}
		}

		.more-shop {
			display: flex;
			align-items: center;
			justify-content: center;
			background-color: #ffffff;
			padding: 27rpx 0;
			color: #999999;
			font-size: 26rpx;

			.icon-ic_rightarrow {
				font-size: 22rpx;
			}
		}
	}
}

.mer_count {
	display: flex;
	flex-wrap: wrap;
	padding: 20rpx;
	align-items: center;

	.item {
		flex: 4;
		height: 140rpx;
		margin: 0 2% 30rpx 0;
		background: #FEFEFF;
		border-radius: 16rpx;
		display: flex;
		align-items: center;
		justify-content: center;

		/deep/uni-image,
		/deep/image,
		/deep/.easy-loadimage {
			width: 100% !important;
			max-height: 140rpx;
		}

		&:nth-child(4n) {
			margin-right: 0;
		}
	}
}


.mer-detail-wrap {
	padding: 10px;
	background-color: #fff;
	margin-bottom: 28rpx;

	.mer-top-info {
		display: flex;
		margin-bottom: 3px;
	}

	.mer-avatar {
		width: 100rpx;
		height: 100rpx;
		border-radius: 10rpx;
		margin-right: 20rpx;
	}

	.mer-info {
		flex: 1;
		overflow: hidden;
	}

	.mer-name {
		display: flex;
		align-items: center;
		margin-top: 12rpx;
		margin-bottom: 18rpx;
		font-size: 28rpx;
		font-weight: 600;
		line-height: 28rpx;
		color: #282828;

		.type-tag {
			height: 32rpx;
			padding: 8rpx;
			display: flex;
			align-items: center;
			margin-left: 8rpx;
			border-radius: 4rpx;
			background: #E93323;
			font-size: 20rpx;
			color: #fff;
		}
	}

	.mer-follow-info {
		display: flex;
		align-items: center;
		font-size: 24rpx;
		color: #666666;

		.vertical-line {
			width: 1px;
			height: 20rpx;
			background-color: #ccc;
			margin: 0 8rpx;
		}
	}

	.product-item {
		width: 152rpx;
		overflow: hidden;
		flex-shrink: 0;
	}

	.product-list-wrapper {
		overflow-x: auto;
		scrollbar-width: none;

		&::-webkit-scrollbar {
			display: none;
		}
	}

	.product-list {
		display: flex;
		gap: 16rpx;
		padding-left: 120rpx;
	}

	.product-image {
		width: 76px;
		height: 76px;
		border-radius: 16rpx;
	}

	.product-name {
		font-size: 12px;
		color: #282828;
		margin-top: 6px;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.product-price {
		margin-top: 4px;
		color: #E93323;
		line-height: 1;
	}
}

.mutip-line {
	.vertical-line {
		width: 1px;
		height: 24rpx;
		margin: 0 8rpx;
		background: #D8D8D8;
	}
}
</style>
